package com.ruoyi.project.para.hours.controller;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.para.hours.domain.ImpAuditBusiHours;
import com.ruoyi.project.para.hours.service.IImpAuditBusiHoursService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 正常营业时间参数Controller
 *
 * @author ruoyi
 * @date 2020-03-14
 */
@Controller
@RequestMapping("/para/hours")
public class ImpAuditBusiHoursController extends BaseController
{
    private String prefix = "para/hours";

    @Autowired
    private IImpAuditBusiHoursService impAuditBusiHoursService;

    @RequiresPermissions("para:hours:view")
    @GetMapping()
    public String hours()
    {
        return prefix + "/hours";
    }

    /**
     * 查询正常营业时间参数列表
     */
    @RequiresPermissions("para:hours:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ImpAuditBusiHours impAuditBusiHours)
    {
        startPage();
        List<ImpAuditBusiHours> list = impAuditBusiHoursService.list(new QueryWrapper<ImpAuditBusiHours>(impAuditBusiHours));
        return getDataTable(list);
    }

    /**
     * 导出正常营业时间参数列表
     */
    @RequiresPermissions("para:hours:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ImpAuditBusiHours impAuditBusiHours)
    {
        List<ImpAuditBusiHours> list = impAuditBusiHoursService.list(new QueryWrapper<ImpAuditBusiHours>(impAuditBusiHours));
        ExcelUtil<ImpAuditBusiHours> util = new ExcelUtil<ImpAuditBusiHours>(ImpAuditBusiHours.class);
        return util.exportExcel(list, "hours");
    }

    /**
     * 新增正常营业时间参数
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存正常营业时间参数
     */
    @RequiresPermissions("para:hours:add")
    @Log(title = "正常营业时间参数", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ImpAuditBusiHours impAuditBusiHours)
    {
        return toAjax(impAuditBusiHoursService.saveOrUpdate(impAuditBusiHours));
    }

    /**
     * 修改正常营业时间参数
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ImpAuditBusiHours impAuditBusiHours = impAuditBusiHoursService.getById(id);
        mmap.put("impAuditBusiHours", impAuditBusiHours);
        return prefix + "/edit";
    }

    /**
     * 修改保存正常营业时间参数
     */
    @RequiresPermissions("para:hours:edit")
    @Log(title = "正常营业时间参数", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ImpAuditBusiHours impAuditBusiHours)
    {
        return toAjax(impAuditBusiHoursService.saveOrUpdate(impAuditBusiHours));
    }

    /**
     * 删除正常营业时间参数
     */
    @RequiresPermissions("para:hours:remove")
    @Log(title = "正常营业时间参数", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(impAuditBusiHoursService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
